<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="供应商" prop="vendorName">
        <el-input
          v-model="queryParams.vendorName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择单据状态" clearable>
          <el-option
            v-for="dict in dict.type.mes_order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="入库日期" prop="createTime">
        <el-date-picker clearable
                        v-model="queryParams.createTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择入库日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="入库类型" prop="isConcession">
        <el-select v-model="queryParams.isConcession" placeholder="请选择入库类型" clearable>
          <el-option label="让步接收" value="Y"/>
          <el-option label="正品入库" value="N"/>
        </el-select>
      </el-form-item>
      <el-form-item label="物料编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入产品物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入产品物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批次号" prop="batchCode">
        <el-input
          v-model="queryParams.batchCode"
          placeholder="请输入入库批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库名称" prop="warehouseName">
        <el-input
          v-model="queryParams.warehouseName"
          placeholder="请输入仓库名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库区名称" prop="locationName">
        <el-input
          v-model="queryParams.locationName"
          placeholder="请输入库区名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库位名称" prop="areaName">
        <el-input
          v-model="queryParams.areaName"
          placeholder="请输入库位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到货单编号" prop="arrivedCode">
        <el-input
          v-model="queryParams.arrivedCode"
          placeholder="请输入到货单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['cg:itemRecptDetailTable:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="itemRecptDetailTableList">
      <el-table-column label="入库单编号" align="center" prop="recptCode"/>
      <el-table-column label="供应商" align="center" prop="vendorName"/>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_order_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="入库日期" align="center" prop="recptDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recptDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="入库类型" align="center" prop="isConcession">
        <template slot-scope="scope">
          <el-span> {{scope.row.isConcession === 'Y' ? '让步接收' : '正品入库'}}</el-span>
        </template>
      </el-table-column>
      <el-table-column label="产品物料编码" align="center" prop="itemCode"/>
      <el-table-column label="产品物料名称" align="center" prop="itemName"/>
      <el-table-column label="规格型号" align="center" prop="specification"/>
      <el-table-column label="主数量" align="center" prop="quantityRecived"/>
      <el-table-column label="主单位" align="center" prop="unitOfMeasure"/>
      <el-table-column label="辅单位数量" align="center" prop="storageUnitQuantity"/>
      <el-table-column label="辅单位" align="center" prop="storageUnit"/>
      <el-table-column label="单价" align="center" prop="price"/>
      <el-table-column label="金额" align="center" prop="amount"/>
      <el-table-column label="批次号" align="center" prop="batchCode"/>
      <el-table-column label="仓库" align="center" prop="warehouseName"/>
      <el-table-column label="库区" align="center" prop="locationName"/>
      <el-table-column label="库位" align="center" prop="areaName"/>
      <el-table-column label="生产日期" align="center" prop="manufactureDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.manufactureDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="有效期" align="center" prop="expireDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expireDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户名称" align="center" prop="clientName"/>
      <el-table-column label="到货单编号" align="center" prop="arrivedCode"/>
      <el-table-column label="订单编号" align="center" prop="orderCode"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {listItemRecptDetailTable} from "@/api/mes/cg/itemRecptDetailTable";

export default {
  name: "ItemRecptDetailTable",
  dicts: ['mes_order_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料入库明细表格数据
      itemRecptDetailTableList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vendorName: null,
        status: null,
        createTime: null,
        isConcession: null,
        itemCode: null,
        itemName: null,
        batchCode: null,
        warehouseName: null,
        locationName: null,
        areaName: null,
        clientName: null,
        arrivedCode: null,
        orderCode: null,
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询物料入库明细列表 */
    getList() {
      this.loading = true;
      listItemRecptDetailTable(this.queryParams).then(response => {
        this.itemRecptDetailTableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cg/itemRecptDetailTable/export', {
        ...this.queryParams
      }, `itemRecptDetailTable_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
